﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Configuration;
using System.Windows.Documents;
using Cinch;
using MEFedMVVM.Common;
using MEFedMVVM.ViewModelLocator;
using MEFedMVVM.Services.Contracts;
using SLS.Core;
using SLS.Controls;
using SLS.Document;
using Slf;
namespace SLS.Presentation
{
    /// <summary>
    /// This ViewModel demonstrates how to use WorkSpaces and Menus. You will
    /// need to look in the MainWindow.xaml and also the AppStyles.xaml ResourceDictionary
    /// to see how the Styles are used to tie up with this ViewModel
    /// </summary>
    [ExportViewModel("DocumentCenterViewModel")]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class DocumentCenterViewModel : ViewModelBase
    {
        #region Data
        private bool showContextMenu = false;
        private IViewAwareStatus viewAwareStatusService;
        private IMessageBoxService messageBoxService;  
 
        private IOpenFileService openFileService;
        private ISaveFileService saveFileService;
        private IUIVisualizerService uiVisualizerService;
        private ILogger iLoggerSevice;
        #endregion 
        #region Ctor
        [ImportingConstructor]
        public DocumentCenterViewModel(
            IMessageBoxService messageBoxService,
            IOpenFileService openFileService,
            ISaveFileService saveFileService,
            IUIVisualizerService uiVisualizerService,
            ILogger iLogger,
            IViewAwareStatus viewAwareStatusService)
        {
            DocumentManagement.Instance.WFEditDocuments = this;
            this.iLoggerSevice = iLogger;
            this.messageBoxService = messageBoxService;
            this.openFileService = openFileService;
            this.saveFileService = saveFileService;
            this.uiVisualizerService = uiVisualizerService; 
            this.viewAwareStatusService = viewAwareStatusService;
            this.viewAwareStatusService.ViewLoaded += ViewAwareStatusService_ViewLoaded;
        }
        #endregion

        #region Private Methods
        /// <summary>
        /// Creates and returns the menu items
        /// </summary>
        private List<WPFMenuItem> CreateMenus()
        {

            List<WPFMenuItem> menu = new List<WPFMenuItem>();

            WPFMenuItem menuActions = new WPFMenuItem("0","Actions");
            menu.Add(menuActions);  
            return menu;
        }

        private void ViewAwareStatusService_ViewLoaded()
        {
            ArrayList assemblylist = new ArrayList();
            assemblylist.Add("CenterWorkFlow");
            /*
            assemblylist.Add("GoodsMasterKeyRelationVW");
            assemblylist.Add("GoodsMasterPropertyVW");
            assemblylist.Add("GoodsMasterAssemblePointVW"); */           
            DocumentManagement.Instance.LoadAssembly(assemblylist);
            /*
            DocumentManagement.Instance.OpenDocument("EditGoodsMasterKeyRelation", "WFEditDocuments");
            DocumentManagement.Instance.OpenDocument("EditGoodsMasterProperty", "WFEditDocuments");
            DocumentManagement.Instance.OpenDocument("EditGoodsMasterAssemblePoint", "WFEditDocuments");
            DocumentManagement.Instance.OpenDocument("EditGoodsMasterKey", "WFEditDocuments"); */
        }

        private void ImageWorkSpace_WorkspaceTabClosing(object sender, CancelEventArgs e)
        {
            e.Cancel = false;
            CustomDialogResults result =
                messageBoxService.ShowYesNo("Are you sure you want to close this tab?",
                    CustomDialogIcons.Question);

            //if user did not want to cancel, keep workspace open
            if (result == CustomDialogResults.No)
            {
                e.Cancel = true;
            }
            //otherwise close workspace, and make sure to unhook WorkspaceTabClosing event
            //to prevent memory leak
            else
            {
                ((WorkspaceData)sender).WorkspaceTabClosing -= ImageWorkSpace_WorkspaceTabClosing;
            }
        }
        #endregion

        #region Public Properties
        /// <summary>
        /// Returns the bindbable Main Window options
        /// </summary>
        public List<WPFMenuItem> MainWindowOptions
        {
            get
            {
                return CreateMenus();
            }
        }


        /// <summary>
        /// ShowContextMenu
        /// </summary>
        static PropertyChangedEventArgs showContextMenuArgs =
            ObservableHelper.CreateArgs<DocumentCenterViewModel>(x => x.ShowContextMenu);

        public bool ShowContextMenu
        {
            get { return showContextMenu; }
            private set
            {
                showContextMenu = value;
                NotifyPropertyChanged(showContextMenuArgs);
            }
        }
        #endregion

    }

}
